package com.syf.controller;

import com.syf.domain.CoinConfig;
import com.syf.model.R;
import com.syf.service.CoinConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author 苏耀奋
 * @create 2021-10-21 20:25
 */
@RestController
@RequestMapping("/coinConfigs")
@Api(tags = "币种(钱包)配置的控制器")
public class CoinConfigController {

    @Autowired
    private CoinConfigService coinConfigService ;

    //http://localhost:9527/finance/coinConfigs/info/1017693208863477761
    @GetMapping("/info/{coinId}")
    @ApiOperation(value = "根据币种Id 查询币种的(钱包)配置信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "coinId" ,value = "币种的id值")
    })
    public R<CoinConfig> getCoinConfig(@PathVariable("coinId") Long coinId){
        CoinConfig coinConfig =  coinConfigService.findByCoinId(coinId) ;
        return R.ok(coinConfig) ;
    }


    @PatchMapping
    @ApiOperation(value = "币种(钱包)配置 的修改/新增操作")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "coinConfig" ,value ="coinConfig的json数据" )
    })
    public R  update(@RequestBody  @Validated CoinConfig coinConfig){
        boolean saveOrUpdate  =  coinConfigService.updateOrSave(coinConfig) ;
        if(saveOrUpdate){
            return R.ok() ;
        }
        return R.fail("修改失败") ;
    }

}
